package question1;

import java.util.Scanner;
import java.util.Stack;

public class Main {
    public static void main(String[] args) {
        MyQueue myQueue = new MyQueue();

        Scanner scanner = new Scanner(System.in);
        String[] operationList = scanner.nextLine().split(",");
        String[] dataList = scanner.nextLine().split(",");

        StringBuilder resultStr = new StringBuilder();

        for (int i = 0; i < operationList.length; i++) {
            switch (operationList[i]) {
                case "push":
                    myQueue.push(Integer.parseInt(dataList[i]));
                    resultStr.append("null").append(",");
                    break;
                case "peek":
                    resultStr.append(myQueue.peek()).append(",");
                    break;
                case "pop":
                    int x = myQueue.pop();
                    resultStr.append(x).append(",");
                    break;
                case "empty":
                    resultStr.append(myQueue.empty() ? "true" : "false").append(",");
                    break;
            }
        }

        System.out.println(resultStr.substring(0, resultStr.length() - 1));
    }

    public static class MyQueue {

        private Stack<Integer> stackIn;

        private Stack<Integer> stackOut;

        public MyQueue() {
            this.stackIn = new Stack<>();
            this.stackOut = new Stack<>();
        }

        void push(int x) {
            stackIn.push(x);
        }

        int pop() {
            if (stackOut.isEmpty()) {
                while (!stackIn.empty()) {
                    stackOut.push(stackIn.pop());
                }
                return stackOut.pop();
            }
            return stackOut.pop();
        }

        int peek() {
            if (stackOut.isEmpty()) {
                while (!stackIn.empty()) {
                    stackOut.push(stackIn.pop());
                }
            }
            return stackOut.peek();
        }

        boolean empty() {
            return stackOut.isEmpty() && stackIn.empty();
        }

    }

}
